// pages/evaluate/evaluate.js
const app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        textData: '',
        currentIndex: 0,
        isSpread: false,
        isSpreads: [false, false, false, false, false, false, false, false],
        orderIds: [],
        evaluateContent: {},
        evaluateIndex:0,
        leftArrShow:true,
        rightArrShow:true
    },

    /**
     * 事件处理
     */
    clickAudio(){
        app.globalData.globalWebUrl = this.data.evaluateContent.VoiceUrl;
        wx.navigateTo({
            url: '/pages/agreement-web/agreement-web?title=语音',
        })
    },
    clickItem(e) {
        let index = e.currentTarget.dataset.index;
        let spread = `isSpreads[${e.currentTarget.dataset.index}]`;
        this.setData({
            currentIndex: index,
            [spread]: !this.data.isSpreads[index]
        });
        console.log(this.data.isSpreads);
    },
    upClick(){
        let index = this.data.evaluateIndex;
        let leftArrShow = true;
        --index;
        if(index <= 0){
            leftArrShow = false;
        }else{
            leftArrShow = true;
        }
        this.setData({
            evaluateIndex:index,
            rightArrShow:true,
            leftArrShow: leftArrShow
        });
        this.getEvaluateById(this.data.orderIds[index]);
    },
    downClick(){
        let index = this.data.evaluateIndex;
        let rightArrShow = true;
        ++index;
        if (index >= this.data.orderIds.length - 1) {
            rightArrShow = false;
        } else {
            rightArrShow = true;
        }
        this.setData({
            evaluateIndex: index,
            leftArrShow: true,
            rightArrShow: rightArrShow
        });
        this.getEvaluateById(this.data.orderIds[index]);
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let orderIds = JSON.parse(options.parmas);
        if (options.userName){
            wx.setNavigationBarTitle({
                title: options.userName
            })
        }
        let rightShow = true;
        if(orderIds.length <= 1){
            rightShow = false;
        }
        this.setData({
            orderIds: orderIds,
            leftArrShow:false,
            rightArrShow: rightShow
        });
        this.getEvaluateById(orderIds[this.data.evaluateIndex]);
    },
    getEvaluateById(id) {
        let that = this;
        wx.showLoading({
            title: '加载中...',
            mask: true
        });
        wx.request({
            url: app.globalData.serverAddress.getEvaluateById,
            data: {
                orderId: id
            },
            header: {
                'Authorization': "Bearer " + app.globalData.token
            },
            method: 'GET',
            success: function(res) {
                if (res.statusCode == 200 && res.data.CodeStatus == 20000) {
                    // console.info(res);
                    that.setData({
                        evaluateContent: res.data.BodyContent
                    })
                }
            },
            fail: function(res) {
                console.error(res);
            },
            complete: function(res) {
                wx.hideLoading();
            },
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})